{% extends 'layout.html' %}
{% block css %}
    <style>
        .container { max-width: 800px; margin: 20px auto; padding: 20px; }
        .upload-form { margin-bottom: 30px; padding: 20px; border: 1px solid #ddd; }
        .file-list { list-style: none; padding: 0; }
        .file-item { padding: 10px; margin: 5px 0; border: 1px solid #eee; }
    </style>
{% endblock %}
{% block content %}
    <div class="container">
        <h1>文件上传</h1>
        <div class="upload-form">
            <form method="post" enctype="multipart/form-data">
                {% csrf_token %}  <!-- 必须添加，防止CSRF攻击 -->
                {{ form.as_p }}
                <button type="submit" class="btn btn-primary">上传</button>
            </form>
        </div>

        <h2>已上传文件</h2>
        {% if files %}
            <ul class="file-list">
                {% for file in files %}
                    <li class="file-item">
                        {{ file.file_name }}
                        <small>(上传于: {{ file.upload_time|date:"Y-m-d H:i" }})</small>
                        <a href="{% url 'file_download' file.id %}" style="margin-left: 10px;">下载</a>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            <p>暂无上传的文件</p>
        {% endif %}
    </div>
{% endblock %}